﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace AvvaMobileNHibernateHelperKit.Controls
{
    public partial class StartPage : UserControl
    {
        public StartPage()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StartPage_Load(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                DataSet ds = new DataSet();
                ds.ReadXml(ApplicationSettings.ApplicationStartupPath + @"\Settings\" + SystemFileNames.RECENT_PROJECTS);
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    ListViewItem item = new ListViewItem(dr["ProjectName"].ToString(), 0);
                    item.SubItems.Add(dr["ProjectID"].ToString());
                    item.SubItems.Add(dr["ProjectTypeID"].ToString());
                    item.SubItems.Add(dr["ProjectSolutionFile"].ToString());
                    listRecentProjects.Items.Add(item);
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }        

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void imgExit_Click(object sender, EventArgs e)
        {
            ((Form)this.FindForm()).Controls["pnlMain"].Controls["pnlContent"].Controls.Clear();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listRecentProjects_DoubleClick(object sender, EventArgs e)
        {
            // ProjectName = listRecentProjects.SelectedItems[0].SubItems[0].Text;
            // ProjectID = listRecentProjects.SelectedItems[0].SubItems[1].Text;
            // ProjectTypeID = listRecentProjects.SelectedItems[0].SubItems[2].Text;
            // ProjectSolutionFile = listRecentProjects.SelectedItems[0].SubItems[3].Text;

            ((MainForm)this.FindForm()).OpenProject(listRecentProjects.SelectedItems[0].SubItems[3].Text);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpenProject_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Nh-Studio Solution File(*.slnx)|*.slnx";
            if (ofd.ShowDialog() == DialogResult.OK && ofd.FileName != null)
            {
                ((MainForm)this.FindForm()).OpenProject(ofd.FileName);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateProject_Click(object sender, EventArgs e)
        {
            new CreateProjectDialog(((MainForm)this.FindForm())).ShowDialog();
        }



    }
}
